<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <table class="layui-table">
            <tr>
                <td style="text-align: center;width: 12%">类型</td>
                <td>
                    <input type="radio" name="type" value="user:sms:code" title="乘客：APP/H5/用户登录/注册/忘记密码" checked>
                    <input type="radio" name="type" value="driver:sms:code" title="司机：APP/H5/用户登录/注册/忘记密码">
                </td>
            </tr>

            <tr>
                <td style="text-align: center;width: 12%">手机号</td>
                <td>
                    <input type="text" name="phone" id="phone" value="" lay-verify="required" placeholder="请输入手机号码" class="layui-input" style="width: 300px;float: left;" onkeyup="num(this)">
                </td>
            </tr>
            <tr>
                <td style="text-align: center;width: 12%">验证码</td>
                <td>
                    <input type="text" name="code" id="code" value="" class="layui-input" style="width: 300px;float: left;" onkeyup="num(this)">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="padding-left: 100px;">
                    <button class="layui-btn" lay-submit lay-filter="*">获取验证码</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form'], function () {
            var form = layui.form;
            form.on('submit(*)', function(data){
                $.ajax({
                    url:'{:url("/admin/SmsCode/index")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            $("#code").val(res.msg);
                        }else{
                            layer.msg(res.msg,{icon: 5});
                            $("#code").val('');
                        }
                    }
                });
                return false;
            });
        });
        //验证只能输入数字
        function num(object) {
            var value   = object.value;
            var id      = object.id;
            if (isNaN(value)){
                layer.msg('请输入正确的数字',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }
    </script>
</block>
